home *** CD-ROM | disk | FTP | other *** search
- /***
- *direct.c - functions for file I/O on directories
- *
- *Copyright (c) 1993-1994, Gregg Jennings. All wrongs reserved.
- * P O Box 200, Falmouth, MA 02541-0200
- *
- *Purpose:
- * Beginning of Unix like directory I/O.
- *
- *Notice:
- * This progam may be freely used and distributed. Any distrubution
- * with modifications must retain the above copyright statement and
- * modifications noted.
- * No pulp-publication, in whole or in part, permitted without
- * permission (magazines or books).
- *******************************************************************************/
-
- /*
-
- Version 1.0 14-Jan-1994
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <direct.h>
- #include <dos.h>
-
- #include "diskio.h"
- #include "dirent.h"
- #include "direct.h"
-
- /***
- *cwdstart() - get starting sector number of current directory
- *
- ****/
-
- dword cwdstart(void)
- {
- int i;
- char cwd[67],tbuf[67];
-
- getcwd(cwd,67); /* get current directory */
- if (strlen(cwd) > 3) /* i.e. not "C:\" */
- {
- char *p,*t; /* temps */
- chdir(".."); /* set to parrent directory */
- strcpy(tbuf,cwd); /* make modifiable copy */
-
- /* get last token (this directory name) */
-
- t = p = strtok(tbuf,"\\");
- while (p && (p = strtok(NULL,"\\")) != NULL)
- t = p;
-
- i = file_start(t); /* get starting cluster of the dir */
- chdir(cwd); /* set back to right directory */
-
- return clustertosector((word)i); /* convert to sector */
- }
- return dir_sector;
- }
-
- /***
- *filestart() - get starting sector number of file
- *
- ****/
-
- int file_start(char *file)
- {
- struct DIR dir;
-
- if (direntry(file,&dir))
- return dir.start;
- else
- return 0;
- }
-
- /***
- *direntry() - get directory entry of file
- *
- ****/
-
- int direntry(char *name, struct DIR *dir)
- {
- int i;
- struct xFCB fcb; /* extended FCB */
- struct xDIR _far *xdir; /* temp extended DIR */
-
- memset(&fcb.name[0],' ',11); /* pad with spaces */
- fcb.ff = 0xff; /* extended FCB flag */
- fcb.a = 0x3f; /* ATTRIB */
- fcb.drive = 0; /* current drive */
-
- /* put in name */
-
- for (i = 0; *name != '.' && *name != '\0'; i++)
- fcb.name[i] = *name++;
- if (*name == '.')
- for (name++, i = 0;*name != '\0'; i++)
- fcb.ext[i] = *name++;
-
- /* force xDIR pointer to DTA */
-
- xdir = (struct xDIR _far *)_dos_getdta();
-
- /* make the call */
-
- if (_dos_xfcb_find(&fcb) == 0)
- {
- _fmemcpy((void _far *)dir,&xdir->name,sizeof(struct DIR));
- return 1;
- }
- return 0;
- }
-
- /***
- *get_volume() - get volume label
- *
- ****/
-
- void get_volume(char *v)
- {
- struct find_t fi;
- char cwd[67];
-
- getcwd(cwd,67); /* get current directory */
- chdir("\\"); /* set root directory */
- if (_dos_findfirst("*.*",_A_VOLID,&fi) == 0)
- {
- int i; /* copy all but the '.' */
- for (i = 0; i < 13; i++)
- if (fi.name[i] != '.')
- *v++ = fi.name[i];
- }
- chdir(cwd);
- }
-
- /***
- *_dos_xfcb_find() - fills DOS DTA with Extended DIR, INT 21/11
- *
- * ver 2.0 13-Jan-1994 save DS
- ****/
-
- #ifdef _QC
-
- int _dos_xfcb_find(struct xFCB *xfcb)
- {
- int r;
- _asm mov dx, WORD PTR [xfcb]
- #ifdef __LARGE__
- _asm push ds
- _asm mov ds, WORD PTR [xfcb+2]
- #endif
- _asm mov ah,0x11
- _asm int 0x21
- #ifdef __LARGE__
- _asm pop ds
- #endif
- _asm sub ah,ah
- _asm mov r,ax
- return r;
- }
-
- #else
-
- #pragma optimize("gle",off)
- #pragma warning(disable:4035)
-
- int _dos_xfcb_find(struct xFCB *xfcb)
- {
- _asm mov dx,WORD PTR [xfcb]
- #ifdef __LARGE__
- _asm push ds
- _asm mov ds,WORD PTR [xfcb+2]
- #endif
- _asm mov ah,0x11
- _asm int 0x21
- #ifdef __LARGE__
- _asm pop ds
- #endif
- _asm sub ah,ah
- }
-
- #endif
-
- /***
- *_dos_getdta() - returns address of DOS DTA (far)
- *
- ****/
-
- #ifdef _QC
-
- void _far *_dos_getdta(void)
- {
- char _far *dta;
-
- _asm mov ah,0x2f
- _asm int 0x21
- _asm mov WORD PTR [dta+2],es
- _asm mov WORD PTR [dta],bx
- return dta;
- }
-
- #else
-
- void _far *_dos_getdta(void)
- {
- _asm mov ah,0x2f
- _asm int 0x21
- _asm mov ax,bx
- _asm mov dx,es
- }
-
- #endif
-